home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-PPC / SYSTEM.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  5KB  |  148 lines

  1. #ifndef __PPC_SYSTEM_H
  2. #define __PPC_SYSTEM_H
  3.  
  4. #include <linux/kdev_t.h>
  5. #include <asm/processor.h>
  6. #include <asm/atomic.h>
  7.  
  8. /*
  9.  * Memory barrier.
  10.  * The sync instruction guarantees that all memory accesses initiated
  11.  * by this processor have been performed (with respect to all other
  12.  * mechanisms that access memory).  The eieio instruction is a barrier
  13.  * providing an ordering (separately) for (a) cacheable stores and (b)
  14.  * loads and stores to non-cacheable memory (e.g. I/O devices).
  15.  *
  16.  * mb() prevents loads and stores being reordered across this point.
  17.  * rmb() prevents loads being reordered across this point.
  18.  * wmb() prevents stores being reordered across this point.
  19.  *
  20.  * We can use the eieio instruction for wmb, but since it doesn't
  21.  * give any ordering guarantees about loads, we have to use the
  22.  * stronger but slower sync instruction for mb and rmb.
  23.  */
  24. #define mb()  __asm__ __volatile__ ("sync" : : : "memory")
  25. #define rmb()  __asm__ __volatile__ ("sync" : : : "memory")
  26. #define wmb()  __asm__ __volatile__ ("eieio" : : : "memory")
  27.  
  28. #define __save_flags(flags)    ({\
  29.     __asm__ __volatile__ ("mfmsr %0" : "=r" ((flags)) : : "memory"); })
  30. #define __save_and_cli(flags)    ({__save_flags(flags);__cli();})
  31.  
  32. /* Data cache block flush - write out the cache line containing the
  33.    specified address and then invalidate it in the cache. */
  34. extern __inline__ void dcbf(void *line)
  35. {
  36.     asm("dcbf %0,%1; sync" : : "r" (line), "r" (0));
  37. }
  38.  
  39. extern __inline__ void __restore_flags(unsigned long flags)
  40. {
  41.         extern atomic_t n_lost_interrupts;
  42.     extern void do_lost_interrupts(unsigned long);
  43.  
  44.         if ((flags & MSR_EE) && atomic_read(&n_lost_interrupts) != 0) {
  45.                 do_lost_interrupts(flags);
  46.         } else {
  47.                 __asm__ __volatile__ ("sync; mtmsr %0; isync"
  48.                               : : "r" (flags) : "memory");
  49.         }
  50. }
  51.  
  52.  
  53. extern void __sti(void);
  54. extern void __cli(void);
  55. extern int _disable_interrupts(void);
  56. extern void _enable_interrupts(int);
  57.  
  58. extern void instruction_dump(unsigned long *);
  59. extern void print_backtrace(unsigned long *);
  60. extern void show_regs(struct pt_regs * regs);
  61. extern void flush_instruction_cache(void);
  62. extern void hard_reset_now(void);
  63. extern void poweroff_now(void);
  64. extern int _get_PVR(void);
  65. extern long _get_L2CR(void);
  66. extern void _set_L2CR(unsigned long);
  67. extern void via_cuda_init(void);
  68. extern void pmac_nvram_init(void);
  69. extern void read_rtc_time(void);
  70. extern void pmac_find_display(void);
  71. extern void giveup_fpu(void);
  72. extern void smp_giveup_fpu(struct task_struct *);
  73. extern void cvt_fd(float *from, double *to, unsigned long *fpscr);
  74. extern void cvt_df(double *from, float *to, unsigned long *fpscr);
  75.  
  76. struct device_node;
  77. extern void note_scsi_host(struct device_node *, void *);
  78.  
  79. struct task_struct;
  80. extern void switch_to(struct task_struct *prev, struct task_struct *next);
  81.  
  82. struct thread_struct;
  83. extern void _switch(struct thread_struct *prev, struct thread_struct *next,
  84.             unsigned long context);
  85.  
  86. struct pt_regs;
  87. extern void dump_regs(struct pt_regs *);
  88.  
  89. #ifndef __SMP__
  90.  
  91. #define cli()    __cli()
  92. #define sti()    __sti()
  93. #define save_flags(flags)    __save_flags(flags)
  94. #define restore_flags(flags)    __restore_flags(flags)
  95. #define save_and_cli(flags)    __save_and_cli(flags)
  96.  
  97. #else /* __SMP__ */
  98.  
  99. extern void __global_cli(void);
  100. extern void __global_sti(void);
  101. extern unsigned long __global_save_flags(void);
  102. extern void __global_restore_flags(unsigned long);
  103. #define cli() __global_cli()
  104. #define sti() __global_sti()
  105. #define save_flags(x) ((x)=__global_save_flags())
  106. #define restore_flags(x) __global_restore_flags(x)
  107.  
  108. #endif /* !__SMP__ */
  109.  
  110. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  111.  
  112. extern unsigned long xchg_u64(void *ptr, unsigned long val);
  113. extern unsigned long xchg_u32(void *ptr, unsigned long val);
  114.  
  115. /*
  116.  * This function doesn't exist, so you'll get a linker error
  117.  * if something tries to do an invalid xchg().
  118.  *
  119.  * This only works if the compiler isn't horribly bad at optimizing.
  120.  * gcc-2.5.8 reportedly can't handle this, but as that doesn't work
  121.  * too well on the alpha anyway..
  122.  */
  123. extern void __xchg_called_with_bad_pointer(void);
  124.  
  125. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  126. #define tas(ptr) (xchg((ptr),1))
  127.  
  128. static inline unsigned long __xchg(unsigned long x, void * ptr, int size)
  129. {
  130.     switch (size) {
  131.     case 4:
  132.         return (unsigned long )xchg_u32(ptr, x);
  133.     case 8:
  134.         return (unsigned long )xchg_u64(ptr, x);
  135.     }
  136.     __xchg_called_with_bad_pointer();
  137.     return x;
  138.  
  139.  
  140. }
  141.  
  142. extern inline void * xchg_ptr(void * m, void * val)
  143. {
  144.     return (void *) xchg_u32(m, (unsigned long) val);
  145. }
  146.  
  147. #endif
  148.